<template>
  <div class="search-top">
    <form action="/">
      <van-search
        v-model="value"
        show-action
        placeholder="商品搜索"
        @input="onSearch"
        @cancel="onCancel"
      />
    </form>
  </div>
</template>

<script>
// import { Toast } from "vant"; getAddhistoryaction
import { getHistory, getAddhistoryaction } from "@/network/search";
export default {
  data() {
    return {
      value: "",
      searchValue: [],
    };
  },
  methods: {
    onSearch(val) {
      // Toast(val);
      console.log(val);
      let keyword = val;
      let word = null;
      let openId = localStorage.getItem("openId");
      const datas = {
        keyword,
        // order: 'desc' // asc 可不传 排序用的
      };
      getHistory(datas).then((res) => {
        // console.log(res);
        this.searchValue = res.keywords;
        // word = res.keywords[0];
        const datas = {
          searchValue: this.searchValue,
          val,
        };
        // this.$emit('historyClick', this.searchValue)
        this.$emit("historyClick", datas);
      });
    },
    onCancel() {
      this.$router.go(-1);
    },
  },
};
</script>

<style>
</style>